package com.imooc.study.imoocstudy.ioencode.serializable;

import java.io.*;

public class ObjectSerializable {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        String file = "C:\\Users\\Administrator\\Desktop\\test.txt";

        // 1. 对象的序列化
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
        Student student = new Student("100","张三",20);

        oos.writeObject(student);
        oos.flush();
        oos.close();

        // 2.反序列化
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
        Student studentIn = (Student)ois.readObject();
        System.out.println(studentIn);

    }
}
